package Z.dailyExercise.holiday;

public class _剑指Offer57和为s的两个数字 {
    /**
     * 数组是递增的 所以采取双指针方法
     * @param nums
     * @param target
     * @return
     */
    public int[] twoSum(int[] nums, int target) {

        int[] res = new int[2];
        int i= 0,j=nums.length-1;

        while (i<j){
            if (nums[i]+nums[j] < target){
                i++;
            }else if (nums[i]+nums[j] > target){
                j--;
            }else {
                res[0] = nums[i];
                res[1] = nums[j];
                break;
            }
        }

        return res;
    }
}
